<template>
  <div class="Con">
    <div class="Con-H">
      <h5>
        管 理 员 补 签&nbsp;&nbsp;&nbsp;&nbsp;<span class="span1"
          >谨 慎 使 用</span
        >
      </h5>
    </div>

    <div class="Con-C">
      <ul>
        <li class="li1">
          <el-select
            v-model="valueRoom"
            placeholder="请选择课室"
            size="small"
            style="margin-right: 10px"
          >
            <el-option v-for="item in Rooms" :key="item" :value="item">
            </el-option>
          </el-select>

          <el-button type="primary" size="small" @click="but1"
            >一 键 补 签<i class="el-icon-thumb"></i
          ></el-button>
        </li>

        <li class="li2">
          <el-input
            v-model="valueTeacher"
            placeholder="请输入教师名字"
            size="small"
            style="margin-right: 10px"
          ></el-input>

          <el-button type="primary" size="small" @click="but2()"
            >一 键 补 签<i class="el-icon-thumb"></i
          ></el-button>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { axios1 } from "@/network";
import Qs from "qs";

export default {
  data() {
    return {
      valueRoom: "",
      valueTeacher: "",
      Rooms: ["", 102, 203, 301, 304, 401, 403, 404, 501, 503, 504],
    };
  },
  methods: {
    but1() {
      if (this.valueRoom == "") {
        this.$message({
          message: "课室不可以为空",
          type: "warning",
          duration: 1200,
        });
      } else {
        this.$confirm(
          "你确定将" + this.valueRoom + "课室的全部课程一键补签?",
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        )
          .then(() => {
            this.roomBuQian();
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除",
              duration: 1200,
            });
          });
      }
    },
    but2() {
      if (this.valueTeacher == "") {
        this.$message({
          message: "教师姓名不可以为空",
          type: "warning",
          duration: 1200,
        });
      } else {
        this.$confirm(
          "你确定将" + this.valueTeacher + "老师的全部课程一键补签?",
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        )
          .then(() => {
            this.teacherBuQian();
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除",
              duration: 1200,
            });
          });
      }
    },

    roomBuQian() {
      let mydata1 = {
        room: this.valueRoom,
      };
      axios1({
        url: "/course/complementSignByRoom",
        method: "post",
        headers: {
          token: this.$store.state.token,
        },
        data: Qs.stringify(mydata1),
      })
        .then((res) => {
          alert("补签成功！");
          location.reload();
        })
        .catch((res) => {
          console.log(res);
          alert("补签失败！！");
        });
    },

    teacherBuQian() {
      let mydata2 = {
        c_teacher: this.valueTeacher,
      };
      axios1({
        url: "/course/complementSignByteacher",
        method: "post",
        headers: {
          token: this.$store.state.token,
        },
        data: Qs.stringify(mydata2),
      })
        .then((res) => {
          // console.log(res)
          if (res.data.resultCode == "200") {
            alert(res.data.msg);
            location.reload();
          } else {
            alert(res.data.msg + "可能教师姓名有误,也可能该教师没有课！");
          }
        })
        .catch((res) => {
          console.log(res);
          alert("补签失败！");
        });
    },
  },
};
</script>

<style scoped>
.Con {
  width: 98%;
  height: 98%;
  margin: auto;
  margin-top: 1%;
  box-shadow: 1px 1px 10px rgb(119, 118, 118);
}
.Con-H {
  width: 100%;
  height: 10%;
  border-bottom: 1px solid rgb(190, 190, 189);
  display: flex;
  align-items: center;
  justify-content: center;
}
.Con-H h5 {
  font-size: 18px;
  color: rgb(99, 100, 100);
}
.span1 {
  font-size: 14px;
  color: rgb(243, 112, 112);
}
.Con-C {
  width: 60%;
  height: 40%;
  margin: auto;
  margin-top: 10%;
  box-shadow: 1px 1px 10px rgb(138, 138, 138);
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}
.Con-C:hover {
  box-shadow: 1px 1px 10px rgb(94, 94, 94);
}
.li1 {
  display: flex;
  justify-content: center;
  align-items: center;
}
.li2 {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 10%;
}
</style>
